document.addEventListener('plusready',function(){
//	plus.nativeUI.showWaiting('加载中...');
	var store_id = plus.storage.getItem('store_id');
	var store_name = plus.storage.getItem('store_name');
	var lat = plus.storage.getItem('lat');
	var lng = plus.storage.getItem('lng');
	$('.store_title').text(store_name);
	$.ajax({ 
		type:"post", 
		url:apiRoot + "?act=index&op=type",
		data:{  
			id:store_id
		}, 
		dataType:'json',
		success:function(data){ 
//			console.log(JSON.stringify(data.guess_recommend));
			if(data){  
				$('.Special').attr('data-id',data.types.gc_id);
				$('.types').text(data.types.gc_name);
				if(data.type){
					$.each(data.type, function(k,v) {
						$('.navigation span').eq(k).text(v.gc_name);
						$('.navigation div').eq(k).attr('data-id',v.gc_id);         //遍历添加赋gc_id值
						$('.navigation div').eq(k).attr('data-name',v.gc_name);         //遍历添加赋gc_id值
					});
				}
				if(data.pics){ 
					var html = '<div class="mui-slider-item mui-slider-item-duplicate">'+
									'<a href="#">'+
										'<img src="'+ pica + data.pics[1].img +'">'+
									'</a>'+
								'</div>'; 
					var kk = 0;
					$.each(data.pics, function(key,val) {
						if(kk < 4){
							kk = kk + 1;
							html += '<div class="mui-slider-item">'+
										'<a href="#">'+
											'<img src="'+ pica + val.img +'">'+
										'</a>'+
									'</div>';
						}
					}); 
					html += '<div class="mui-slider-item">'+
									'<a href="#">'+
										'<img src="'+ pica + data.pics[1].img +'">'+
									'</a>'+
								'</div>'; 
					$('.mui-slider-loop').html(html);
				}
				if(data.guess_like){
					var like = '';
	                $.each(data.guess_like, function(k1,v1) {
						like += '<div class="Hot frien_img" data-id="'+ v1.goods_id.goods_id +'" data-did="'+ v1.store_id +'">'+
									'<div class="home_top">'+
										'<img src="'+ pics + v1.store_id + '/' + v1.goods_image +'"/>'+
									'</div>'+
									'<div class="frien_bq">'+																				
										'<div class="mui-ellipsis-2">'+ v1.goods_name +'</div>'+															
									'<b class="red">￥'+ v1.goods_price +'</b>'+													
									'</div>'+				
								'</div>';           	
	                }); 
	                $('.guess_like').html(like);
               }
                if(data.guess_recommend){
                	$.each(data.guess_recommend, function(key,val) {
                		$('.comment_pic').eq(key).attr('src',pics + val.goods_content.store_id + '/' + val.goods_content.goods_image);
                		$('.ify_type').eq(key).text(val.goods_type[0]);
                		$('.ify_name').eq(key).text(val.goods_type[1]);
                		$('.recommend').eq(key).attr('data-cart_id',val.goods_content.gc_id);
                		$('.recommend').eq(key).attr('data-goods_id',val.goods_content.goods_id);
                		$('.recommend').eq(key).attr('data-store_id',val.goods_content.store_id);
                	})
                }
			}
			
			plus.nativeUI.closeWaiting();
			//商品推荐位置
			$('.recommend').unbind('tap');
			$('.recommend').on('tap',function(){
				var _this = $(this);
				var gc_id_1 = _this.attr('data-cart_id');
				var goods_id = _this.attr('data-goods_id');
				var store_id = _this.attr('data-store_id');
				if(gc_id_1 == '1059'){ 
//					console.log(1);
					goods_details(goods_id,store_id,'Travel_details.html');
				}else if(gc_id_1 == '1060'){
//					console.log(2);
					goods_details(goods_id,store_id,'Driving_details.html');
				}else if(gc_id_1 == '1062'){
//					console.log(3);
					goods_details(goods_id,store_id,'Flea_details.html');
				}else{
					goods_details(goods_id,store_id,'goods_details.html');
				}
			})
			
			
			
			//详情
			$('.Hot').unbind('tap');
			$('.Hot').on('tap',function(){
				var _this = $(this);
				var goodsid = _this.attr('data-id');
				var store_id = _this.attr('data-did');
				var nwaiting = plus.nativeUI.showWaiting();//显示原生等待框
				var webviewContent= plus.webview.create('./goods_details.html','goods_details.html',{},{goodsid:goodsid,store_id:store_id});//后台创建webview并打开show.html
				webviewContent.addEventListener("loaded", function() { //注册新webview的载入完成事件
			        nwaiting.close(); //新webview的载入完毕后关闭等待框
			        webviewContent.show("slide-in-right",500); //把新webview窗体显示出来，显示动画效果为速度200毫秒的右侧移入动画
			    }, false);
			})
			//分类
			$('.class_type').unbind('tap');
			$('.class_type').on('tap',function(){
				var _this = $(this);
				var cart_id = _this.attr('data-id');
				var cart_name = _this.attr('data-name');
				var store_id = _this.attr('data-store_id');
				var nwaiting = plus.nativeUI.showWaiting();//显示原生等待框
				var webviewContent= plus.webview.create('./Mobile.html','Mobile.html',{},{cart_id:cart_id,store_id:store_id,cart_name:cart_name});//后台创建webview并打开show.html
				webviewContent.addEventListener("loaded", function() { //注册新webview的载入完成事件
			        nwaiting.close(); //新webview的载入完毕后关闭等待框
			        webviewContent.show("slide-in-right",500); //把新webview窗体显示出来，显示动画效果为速度200毫秒的右侧移入动画
			    }, false);
			})
			//旅游
			$('.class_type1').unbind('tap');
			$('.class_type1').on('tap',function(){
				var _this = $(this);
				var cart_id = _this.attr('data-id');
				var cart_name = _this.attr('data-name');
				var nwaiting = plus.nativeUI.showWaiting();//显示原生等待框
				var webviewContent= plus.webview.create('./Travel.html','Travel.html',{},{cart_id:cart_id,cart_name:cart_name});//后台创建webview并打开show.html
				webviewContent.addEventListener("loaded", function() { //注册新webview的载入完成事件
			        nwaiting.close(); //新webview的载入完毕后关闭等待框
			        webviewContent.show("slide-in-right",500); //把新webview窗体显示出来，显示动画效果为速度200毫秒的右侧移入动画
			    }, false);
			})
			//毕业照
			$('.class_type3').unbind('tap');
			$('.class_type3').on('tap',function(){
				var _this = $(this);
				var cart_id = _this.attr('data-id');
				var nwaiting = plus.nativeUI.showWaiting();//显示原生等待框
				var webviewContent= plus.webview.create('./Graduation.html','Graduation.html',{},{cart_id:cart_id});//后台创建webview并打开show.html
				webviewContent.addEventListener("loaded", function() { //注册新webview的载入完成事件
			        nwaiting.close(); //新webview的载入完毕后关闭等待框
			        webviewContent.show("slide-in-right",500); //把新webview窗体显示出来，显示动画效果为速度200毫秒的右侧移入动画
			    }, false);
			})
			//特价抢购
			$('.Special').unbind('tap');
			$('.Special').on('tap',function(){
				var _this = $(this);
				var cart_id = _this.attr('data-id');
				var nwaiting = plus.nativeUI.showWaiting();//显示原生等待框
				var webviewContent= plus.webview.create('./Special.html','Special.html',{},{cart_id:cart_id});//后台创建webview并打开show.html
				webviewContent.addEventListener("loaded", function() { //注册新webview的载入完成事件
			        nwaiting.close(); //新webview的载入完毕后关闭等待框
			        webviewContent.show("slide-in-right",500); //把新webview窗体显示出来，显示动画效果为速度200毫秒的右侧移入动画
			    }, false);
			}) 
			//驾校
			$('.class_type2').unbind('tap');
			$('.class_type2').on('tap',function(){
				var _this = $(this);
				var cart_id = _this.attr('data-id');
				var nwaiting = plus.nativeUI.showWaiting();//显示原生等待框
				var webviewContent= plus.webview.create('./Driving_school.html','Driving_school.html',{},{cart_id:cart_id});//后台创建webview并打开show.html
				webviewContent.addEventListener("loaded", function() { //注册新webview的载入完成事件
			        nwaiting.close(); //新webview的载入完毕后关闭等待框
			        webviewContent.show("slide-in-right",500); //把新webview窗体显示出来，显示动画效果为速度200毫秒的右侧移入动画
			    }, false);
			})
			//跳蚤
			$('.class_type4').unbind('tap');
			$('.class_type4').on('tap',function(){
				var _this = $(this); 
				var cart_id = _this.attr('data-id');
				var cart_name = _this.attr('data-name');
				var nwaiting = plus.nativeUI.showWaiting();//显示原生等待框
				var webviewContent= plus.webview.create('./Flea_market.html','Flea_market.html',{},{cart_id:cart_id,cart_name:cart_name});//后台创建webview并打开show.html
				webviewContent.addEventListener("loaded", function() { //注册新webview的载入完成事件
			        nwaiting.close(); //新webview的载入完毕后关闭等待框
			        webviewContent.show("slide-in-right",500); //把新webview窗体显示出来，显示动画效果为速度200毫秒的右侧移入动画
			    }, false);
			})
			
		},
		error:function(e){  
			console.log(JSON.stringify(e));
			plus.nativeUI.closeWaiting();
			toast('加载失败！');
		}
	});
},false);
function goods_details(goods_id,store_id,spage){
	var nwaiting = plus.nativeUI.showWaiting();//显示原生等待框
	var webviewContent= plus.webview.create(spage,spage,{},{goodsid:goods_id,store_id:store_id});//后台创建webview并打开show.html
	webviewContent.addEventListener("loaded", function() { //注册新webview的载入完成事件
        nwaiting.close(); //新webview的载入完毕后关闭等待框
        webviewContent.show("slide-in-right",500); //把新webview窗体显示出来，显示动画效果为速度200毫秒的右侧移入动画
    }, false);
}
